package com.example.parking.interfaces.http;

import com.example.parking.application.ParkingLotService;
import com.example.parking.domain.model.ParkingLot;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/lots")
public class ParkingLotController {
    private final ParkingLotService parkingLotService;

    public ParkingLotController(ParkingLotService parkingLotService) {
        this.parkingLotService = parkingLotService;
    }

    @GetMapping
    public List<ParkingLot> list() {
        return parkingLotService.listAll();
    }

    @GetMapping("/{id}")
    public ParkingLot get(@PathVariable Long id) {
        return parkingLotService.getById(id);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public ParkingLot create(@RequestBody ParkingLot lot) {
        return parkingLotService.create(lot);
    }

    @PutMapping("/{id}")
    public ParkingLot update(@PathVariable Long id, @RequestBody ParkingLot lot) {
        return parkingLotService.update(id, lot);
    }

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void delete(@PathVariable Long id) {
        parkingLotService.delete(id);
    }
}


